import HTMLParser
import urllib
import re


urlString="http://nixi.in/index.php?option=com_member&amp;Itemid=43"
check=False
check2=False
check3=False
urlText=[]

class ParseIXP(HTMLParser.HTMLParser):
    def handle_starttag(self,tag,attrs):
        global check
        global check2
        if tag=="h2":
            check2=True
        if tag=="td":
            check=True
                  
    def handle_endtag(self,tag):
        global check2
        global check3
        if tag=="h2" and check2:
            check3=True
        if tag=="h2" and not check2:
            check3=False
              
    def handle_data(self,data):
        global check
        global check2
        global check3
        if data!='\n' and check2:
            if(data !="Mumbai"):
                check2=False
        if data!='\n' and check==True and check3:
            if(re.search("^\d\d*$",data)):
                urlText.append(data)
                check=False    
           
    def unknown_decl(self,data):
        pass
            
lparser=ParseIXP()
lparser.feed(urllib.urlopen(urlString).read())


filePath="ixp_members.txt"
file = open(filePath,"a")
for item in urlText:
    #print item
    print >> file, "115 %s" % item
file.close()